load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_integration_test", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "write_ops_exec_util",
    srcs = [
        "write_ops_exec_util.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/repl:repl_coordinator_interface",
    ],
)

mongo_cc_library(
    name = "parsed_update",
    srcs = [
        "parsed_update.cpp",
        "parsed_update_array_filters.cpp",
    ],
    deps = [
        "//src/mongo/db:disk_use_options_idl",
        "//src/mongo/db:query_expressions",
        "//src/mongo/db:server_base",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/matcher:expressions_mongod_only",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/update:update_driver",
    ],
)

mongo_cc_library(
    name = "canonical_update_and_delete",
    srcs = [
        "canonical_update.cpp",
        "parsed_delete.cpp",
        "update_result.cpp",
    ],
    deps = [
        "delete_request_idl",
        "parsed_update",
        "//src/mongo:base",
        "//src/mongo/db:not_primary_error_tracker",
        "//src/mongo/db:query_expressions",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/db/matcher:expressions_mongod_only",
        "//src/mongo/db/pipeline/process_interface:mongo_process_interface",
        "//src/mongo/db/query:canonical_query_base",
        "//src/mongo/db/query:plan_yield_policy",
        "//src/mongo/db/storage:feature_document_util",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/update:update_driver",
    ],
)

idl_generator(
    name = "single_write_result_gen",
    src = "single_write_result.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/query/client_cursor:cursor_response_gen",
    ],
)

mongo_cc_library(
    name = "write_ops",
    srcs = [
        "delete.cpp",
        "insert.cpp",
        "update.cpp",
        "write_ops_retryability.cpp",
        ":single_write_result_gen",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:mongod_options",
        "//src/mongo/db:profile_collection",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:service_context",
        "//src/mongo/db/matcher:expressions_mongod_only",
        "//src/mongo/db/query:command_request_response",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/query/util:validate_id",
        "//src/mongo/db/repl:image_collection_entry",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/update:update_driver",
    ],
)

idl_generator(
    name = "write_ops_gen",
    src = "write_ops.idl",
    deps = [
        "//src/mongo/crypto:fle_field_schema_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/auth:access_checks_gen",
        "//src/mongo/db/auth:action_type_gen",
        "//src/mongo/db/pipeline:legacy_runtime_constants_gen",
        "//src/mongo/db/query:hint_gen",
        "//src/mongo/db/query/client_cursor:cursor_response_gen",
        "//src/mongo/db/session:logical_session_id_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

mongo_cc_library(
    name = "write_ops_parsers",
    srcs = [
        "write_ops.cpp",
        ":write_ops_gen",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/crypto:encrypted_field_config",
        "//src/mongo/crypto:fle_fields",
        "//src/mongo/db:dbmessage",
        "//src/mongo/db:server_base",
        "//src/mongo/db/auth:authprivilege",
        "//src/mongo/db/pipeline:runtime_constants_idl",
        "//src/mongo/db/query:hint_parser",
        "//src/mongo/db/query/client_cursor:cursor_response_idl",
        "//src/mongo/db/repl:optime",
        "//src/mongo/idl:idl_parser",
        "//src/mongo/rpc:command_status",
        "//src/mongo/rpc:metadata_impersonated_user",
    ],
)

mongo_cc_library(
    name = "write_ops_parsers_test_helpers",
    srcs = [
        "write_ops_parsers_test_helpers.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:dbmessage",
    ],
)

idl_generator(
    name = "delete_request_gen",
    src = "delete_request.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/pipeline:legacy_runtime_constants_gen",
        "//src/mongo/db/query:hint_gen",
        "//src/mongo/db/session:logical_session_id_gen",
    ],
)

mongo_cc_library(
    name = "delete_request_idl",
    srcs = [
        ":delete_request_gen",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db/pipeline",
        "//src/mongo/db/pipeline:runtime_constants_idl",
    ],
)

mongo_cc_library(
    name = "write_ops_exec",
    srcs = [
        "write_ops_exec.cpp",
    ],
    deps = [
        ":write_ops",
        ":write_ops_exec_util",
        "//src/mongo:base",
        "//src/mongo/db:curop_metrics",
        "//src/mongo/db:dbhelpers",
        "//src/mongo/db:profile_collection",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/query:explain_diagnostic_printer",
        "//src/mongo/db/query:shard_key_diagnostic_printer",
        "//src/mongo/db/query/query_settings:query_settings_service",
        "//src/mongo/db/query/query_shape:update_cmd_shape",
        "//src/mongo/db/query/query_stats",
        "//src/mongo/db/query/query_stats:update_key",
        "//src/mongo/db/repl:oplog",
        "//src/mongo/db/repl:repl_coordinator_interface",
        "//src/mongo/db/s:query_analysis_writer",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/shard_role/shard_catalog:catalog_helpers",
        "//src/mongo/db/shard_role/shard_catalog:collection_options",
        "//src/mongo/db/stats:counters",
        "//src/mongo/db/stats:server_read_concern_write_concern_metrics",
        "//src/mongo/db/stats:top",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/timeseries:bucket_compression",
        "//src/mongo/db/timeseries:bucket_compression_failure",
        "//src/mongo/db/timeseries:collection_pre_conditions_util",
        "//src/mongo/db/timeseries:timeseries_conversion_util",
        "//src/mongo/db/timeseries:timeseries_options",
        "//src/mongo/db/timeseries:timeseries_write_util",
        "//src/mongo/db/timeseries/bucket_catalog",
        "//src/mongo/db/timeseries/write_ops:timeseries_write_ops_utils",
        "//src/mongo/db/transaction",
        "//src/mongo/db/transaction:transaction_api",
        "//src/mongo/executor:inline_executor",
        "//src/mongo/s:query_analysis_sampler",
        "//src/mongo/util:log_and_backoff",
    ],
)

mongo_cc_unit_test(
    name = "db_ops_test",
    srcs = [
        "write_ops_exec_test.cpp",
        "write_ops_parsers_test.cpp",
        "write_ops_retryability_test.cpp",
    ],
    tags = ["mongo_unittest_first_group"],
    deps = [
        ":write_ops",
        ":write_ops_exec",
        ":write_ops_parsers",
        ":write_ops_parsers_test_helpers",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:record_id_helpers",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/collection_crud",
        "//src/mongo/db/op_observer",
        "//src/mongo/db/repl:mock_repl_coord_server_fixture",
        "//src/mongo/db/repl:oplog_entry",
        "//src/mongo/db/session:session_catalog",
        "//src/mongo/db/shard_role/shard_catalog:catalog_test_fixture",
        "//src/mongo/db/timeseries:bucket_compression",
        "//src/mongo/db/transaction",
    ],
)

mongo_cc_integration_test(
    name = "db_ops_integration_test",
    srcs = [
        "write_ops_document_stream_integration_test.cpp",
    ],
    deps = [
        "//src/mongo/client:clientdriver_network",
        "//src/mongo/transport:transport_layer_egress_init",
        "//src/mongo/util:version_impl",
    ],
)
